package com.ymatou.iapi.coupon.testcase;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.coupon.parameter.UserReceiveCouponBean;
import com.ymatou.iapi.coupon.parameter.getUserExpiringAmountBean;
import com.ymatou.iapi.coupon.service.UserReceiveCouponCall;
import com.ymatou.iapi.coupon.service.getUserExpiringAmountCall;
import com.ymatou.iapi.couponmanage.parameter.CreateCouponBean;
import com.ymatou.iapi.couponmanage.parameter.SellerCreateBatchBean;
import com.ymatou.iapi.couponmanage.service.CreateCouponCall;
import com.ymatou.iapi.couponmanage.service.SellerCreateBatchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponServiceMCallServiceV2;
import com.ymttest.database.sqlwapper.couponWapper;
import com.ymttest.database.sqlwapper.couponbatchWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
/**
*获取用户即将过期的优惠券面额
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getUserExpiringAmount{
	private static getUserExpiringAmountBean getuserexpiringamountBean;
	private static getUserExpiringAmountCall getuserexpiringamountCall;
	private couponbatchWapper couponbatchWapper=new couponbatchWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取用户即将过期的优惠券面额");
	}

	@Before
	public void caseUp() {
		getuserexpiringamountBean=new getUserExpiringAmountBean();
		getuserexpiringamountCall=new getUserExpiringAmountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getuserexpiringamountCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUserExpiringAmount_001() {
		Logger.start(true,"获取用户即将过期的优惠券面额");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();

			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);

			UserReceiveCouponBean userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(userId);
			UserReceiveCouponCall userReceiveCouponCall=couponCallService.receiveCouponInfo(createCouponCall.getBatchCode(),userreceivecouponBean.getUserId());		
			
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	        Date dnow = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -5); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, 2); // 设置为后2天
	        dAfter = calendar2.getTime(); // 得到后2天的时间
	        
	        Calendar calendar3 = Calendar.getInstance(); // 得到日历
	        calendar3.setTime(dNow);// 把当前时间赋给日历
	        calendar3.add(Calendar.DAY_OF_MONTH, 0); // 设置为前1天
	        dnow = calendar3.getTime(); // 得到前一天的时间
	        
	        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
	        System.out.println(sdf.format(dBefore));
	        System.out.println(sdf.format(dAfter));
	        System.out.println(sdf.format(dnow));
	        
	        new couponWapper().setValidStartByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dBefore);
	    	new couponWapper().setValidEndByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dAfter);
			
			getuserexpiringamountBean.setUserId(userreceivecouponBean.getUserId());
			getuserexpiringamountCall.setData(getuserexpiringamountBean);
			getuserexpiringamountCall.callService();	
			//计算面值总值
			String couponValue=new couponbatchWapper().getCouponValueByValidEnd(userId,sdf.format(dnow),getuserexpiringamountBean.getPlatformSource()).stripTrailingZeros().toString();
			
			Logger.verifyEquals("0", getuserexpiringamountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getuserexpiringamountCall.getMessage(), "验证返回Message");
			Logger.verifyEquals(0, getuserexpiringamountCall.getDataErrorCode(), "验证返回Data中的ErrorCode");
			Logger.verifyEquals("null", getuserexpiringamountCall.getDataErrorMessage(), "验证返回Data中的ErrorMessage");
			Logger.verifyEquals(couponValue, getuserexpiringamountCall.getAmount(), "验证返回Data中的Amount");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUserExpiringAmount_002() {
		Logger.start(false,"获取用户即将过期的优惠券面额-优惠券结束时间距当前超过2天-返回：获取不到面额");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();

			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);

			UserReceiveCouponBean userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(userId);
			UserReceiveCouponCall userReceiveCouponCall=couponCallService.receiveCouponInfo(createCouponCall.getBatchCode(),userreceivecouponBean.getUserId());		
			
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	        Date dnow = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -5); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, -1); // 设置为前1天
	        dAfter = calendar2.getTime(); // 得到前1天的时间
	        
	        Calendar calendar3 = Calendar.getInstance(); // 得到日历
	        calendar3.setTime(dNow);// 把当前时间赋给日历
	        calendar3.add(Calendar.DAY_OF_MONTH, 0); // 设置为前1天
	        dnow = calendar3.getTime(); // 得到前一天的时间
	        
	        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
	        System.out.println(sdf.format(dBefore));
	        System.out.println(sdf.format(dAfter));
	        System.out.println(sdf.format(dnow));
	        
	        new couponWapper().setValidStartByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dBefore);
	    	new couponWapper().setValidEndByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dAfter);
			
			getuserexpiringamountBean.setUserId(userreceivecouponBean.getUserId());
			getuserexpiringamountCall.setData(getuserexpiringamountBean);
			getuserexpiringamountCall.callService();	
			
			Logger.verifyEquals("0", getuserexpiringamountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getuserexpiringamountCall.getMessage(), "验证返回Message");
			Logger.verifyEquals(0, getuserexpiringamountCall.getDataErrorCode(), "验证返回Data中的ErrorCode");
			Logger.verifyEquals("null", getuserexpiringamountCall.getDataErrorMessage(), "验证返回Data中的ErrorMessage");
			Logger.verifyEquals("0", getuserexpiringamountCall.getAmount(), "验证返回Data中的Amount");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_getUserExpiringAmount_003() {
		Logger.start(true,"获取用户即将过期的优惠券面额-优惠券结束时间等于当前时间");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);

			UserReceiveCouponBean userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(userId);
			UserReceiveCouponCall userReceiveCouponCall=couponCallService.receiveCouponInfo(createCouponCall.getBatchCode(),userreceivecouponBean.getUserId());		
			
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	       // Date dnow = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -5); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, 0); // 设置为前1天
	        dAfter = calendar2.getTime(); // 得到前1天的时间
	        
//	        Calendar calendar3 = Calendar.getInstance(); // 得到日历
//	        calendar3.setTime(dNow);// 把当前时间赋给日历
//	        calendar3.add(Calendar.DAY_OF_MONTH, 0); // 设置为前1天
//	        dnow = calendar3.getTime(); // 得到前一天的时间
	        
	        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
	        System.out.println(sdf.format(dBefore));
	        System.out.println(sdf.format(dAfter));
//	        System.out.println(sdf.format(dnow));
	        
	        new couponWapper().setValidStartByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dBefore);
	    	new couponWapper().setValidEndByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dAfter);
			
			getuserexpiringamountBean.setUserId(userreceivecouponBean.getUserId());
			getuserexpiringamountCall.setData(getuserexpiringamountBean);
			getuserexpiringamountCall.callService();	
			//计算面值总值
			String couponValue=new couponbatchWapper().getCouponValueByValidEnd(userId,sdf.format(dAfter),getuserexpiringamountBean.getPlatformSource()).stripTrailingZeros().toString();
			
			Logger.verifyEquals("0", getuserexpiringamountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getuserexpiringamountCall.getMessage(), "验证返回Message");
			Logger.verifyEquals(0, getuserexpiringamountCall.getDataErrorCode(), "验证返回Data中的ErrorCode");
			Logger.verifyEquals("null", getuserexpiringamountCall.getDataErrorMessage(), "验证返回Data中的ErrorMessage");
			Logger.verifyEquals(couponValue, getuserexpiringamountCall.getAmount(), "验证返回Data中的Amount");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUserExpiringAmount_005() {
		Logger.start(true,"获取用户即将过期的优惠券面额-优惠券已经使用");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);

			UserReceiveCouponBean userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(userId);
			UserReceiveCouponCall userReceiveCouponCall=couponCallService.receiveCouponInfo(createCouponCall.getBatchCode(),userreceivecouponBean.getUserId());		
			
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	       // Date dnow = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -5); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, 1); // 设置为前1天
	        dAfter = calendar2.getTime(); // 得到前1天的时间
	        
	        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
	        System.out.println(sdf.format(dBefore));
	        System.out.println(sdf.format(dAfter));
	        
	        new couponWapper().setValidStartByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dBefore);
	    	new couponWapper().setValidEndByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dAfter);
			
	    	new couponWapper().setIsUsedByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(),1);
	    	
			getuserexpiringamountBean.setUserId(userreceivecouponBean.getUserId());
			getuserexpiringamountCall.setData(getuserexpiringamountBean);
			getuserexpiringamountCall.callService();	
			//计算面值总值
			//String couponValue=new couponbatchWapper().getCouponValueByValidEnd(sdf.format(dAfter)).stripTrailingZeros().toString();
			
			Logger.verifyEquals("0", getuserexpiringamountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getuserexpiringamountCall.getMessage(), "验证返回Message");
			Logger.verifyEquals(0, getuserexpiringamountCall.getDataErrorCode(), "验证返回Data中的ErrorCode");
			Logger.verifyEquals("null", getuserexpiringamountCall.getDataErrorMessage(), "验证返回Data中的ErrorMessage");
			Logger.verifyEquals("0", getuserexpiringamountCall.getAmount(), "验证返回Data中的Amount");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_getUserExpiringAmount_004() {
		Logger.start(false,"获取用户即将过期的优惠券面额-userId为空");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();

			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);

			UserReceiveCouponBean userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(userId);
			UserReceiveCouponCall userReceiveCouponCall=couponCallService.receiveCouponInfo(createCouponCall.getBatchCode(),userreceivecouponBean.getUserId());		
			
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -5); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, -1); // 设置为前1天
	        dAfter = calendar2.getTime(); // 得到前1天的时间
	        
	        new couponWapper().setValidStartByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dBefore);
	    	new couponWapper().setValidEndByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dAfter);
			
			//getuserexpiringamountBean.setUserId(userreceivecouponBean.getUserId());
			getuserexpiringamountCall.setData(getuserexpiringamountBean);
			getuserexpiringamountCall.callService();	
			
			Logger.verifyEquals("1", getuserexpiringamountCall.getCode(), "验证返回code");
			Logger.verifyEquals(true, getuserexpiringamountCall.getMessage().contains("userId:userid must"), "验证返回Message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUserExpiringAmount_006() {
		Logger.start(false,"获取用户即将过期的优惠券面额-未生效");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();

			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);

			UserReceiveCouponBean userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(userId);
			UserReceiveCouponCall userReceiveCouponCall=couponCallService.receiveCouponInfo(createCouponCall.getBatchCode(),userreceivecouponBean.getUserId());		
			
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	        Date dnow = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, 1); // 设置为前5天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, 2); // 设置为后2天
	        dAfter = calendar2.getTime(); // 得到后2天的时间
	        
	        Calendar calendar3 = Calendar.getInstance(); // 得到日历
	        calendar3.setTime(dNow);// 把当前时间赋给日历
	        calendar3.add(Calendar.DAY_OF_MONTH, 0); // 设置为前1天
	        dnow = calendar3.getTime(); // 得到前一天的时间
	        
	        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
	        System.out.println(sdf.format(dBefore));
	        System.out.println(sdf.format(dAfter));
	        System.out.println(sdf.format(dnow));
	        
	        new couponWapper().setValidStartByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dBefore);
	    	new couponWapper().setValidEndByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dAfter);
			
			getuserexpiringamountBean.setUserId(userreceivecouponBean.getUserId());
			getuserexpiringamountCall.setData(getuserexpiringamountBean);
			getuserexpiringamountCall.callService();	
			//计算面值总值
			String couponValue=new couponbatchWapper().getCouponValueByValidEnd(userId,sdf.format(dnow),getuserexpiringamountBean.getPlatformSource()).stripTrailingZeros().toString();
			
			Logger.verifyEquals("0", getuserexpiringamountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getuserexpiringamountCall.getMessage(), "验证返回Message");
			Logger.verifyEquals(0, getuserexpiringamountCall.getDataErrorCode(), "验证返回Data中的ErrorCode");
			Logger.verifyEquals("null", getuserexpiringamountCall.getDataErrorMessage(), "验证返回Data中的ErrorMessage");
			Logger.verifyEquals("0", getuserexpiringamountCall.getAmount(), "验证返回Data中的Amount");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUserExpiringAmount_007() {
		Logger.start(true,"获取用户即将过期的优惠券面额-商家券-分销");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			CouponServiceMCallServiceV2 couponMCallService = new CouponServiceMCallServiceV2();
			SellerCreateBatchBean sellerCreateBatchBean = couponMCallService.setDefaultSellerCreateBatchBean();
			//分销 修改platformSource=1
			SellerCreateBatchCall sellerCreateBatchCall = couponMCallService.SellerCreateBatch(sellerCreateBatchBean);
			couponbatchWapper.setPlatformSource(1, sellerCreateBatchCall.getBatchCode());
			UserReceiveCouponCall userReceiveCouponCall=couponMCallService.receiveCouponInfo(sellerCreateBatchCall.getBatchCode(),userId);//领取优惠券
					
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	        Date dnow = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -5); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, 2); // 设置为后2天
	        dAfter = calendar2.getTime(); // 得到后2天的时间
	        
	        Calendar calendar3 = Calendar.getInstance(); // 得到日历
	        calendar3.setTime(dNow);// 把当前时间赋给日历
	        calendar3.add(Calendar.DAY_OF_MONTH, 0); // 设置为前1天
	        dnow = calendar3.getTime(); // 得到前一天的时间
	        
	        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
	        System.out.println(sdf.format(dBefore));
	        System.out.println(sdf.format(dAfter));
	        System.out.println(sdf.format(dnow));
	        
	        new couponWapper().setValidStartByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dBefore);
	    	new couponWapper().setValidEndByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dAfter);
			
	    	getuserexpiringamountBean.setPlatformSource(1);//分销
			getuserexpiringamountBean.setUserId(userId);
			getuserexpiringamountCall.setData(getuserexpiringamountBean);
			getuserexpiringamountCall.callService();	
			//计算面值总值
			String couponValue=new couponbatchWapper().getCouponValueByValidEnd(userId,sdf.format(dnow),getuserexpiringamountBean.getPlatformSource()).stripTrailingZeros().toString();
			
			Logger.verifyEquals("0", getuserexpiringamountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getuserexpiringamountCall.getMessage(), "验证返回Message");
			Logger.verifyEquals(0, getuserexpiringamountCall.getDataErrorCode(), "验证返回Data中的ErrorCode");
			Logger.verifyEquals("null", getuserexpiringamountCall.getDataErrorMessage(), "验证返回Data中的ErrorMessage");
			Logger.verifyEquals(couponValue, getuserexpiringamountCall.getAmount(), "验证返回Data中的Amount");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUserExpiringAmount_008() {
		Logger.start(true,"获取用户即将过期的优惠券面额-商家券+平台券-分销");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			
			CouponServiceMCallServiceV2 couponMCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createCouponBean.setAcquireCouponMethod(1);
			CreateCouponCall createCouponCall = couponMCallService.createPlatformCoupon(createCouponBean);
			UserReceiveCouponCall userReceiveCouponCall=couponMCallService.receiveCouponInfo(createCouponCall.getBatchCode(),userId);//领取优惠券
			
			SellerCreateBatchBean sellerCreateBatchBean = couponMCallService.setDefaultSellerCreateBatchBean();
			//分销 修改platformSource=1
			SellerCreateBatchCall sellerCreateBatchCall = couponMCallService.SellerCreateBatch(sellerCreateBatchBean);
			couponbatchWapper.setPlatformSource(1, sellerCreateBatchCall.getBatchCode());
			UserReceiveCouponCall userReceiveCouponCall2=couponMCallService.receiveCouponInfo(sellerCreateBatchCall.getBatchCode(),userId);//领取优惠券
					
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	        Date dnow = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -5); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, 2); // 设置为后2天
	        dAfter = calendar2.getTime(); // 得到后2天的时间
	        
	        Calendar calendar3 = Calendar.getInstance(); // 得到日历
	        calendar3.setTime(dNow);// 把当前时间赋给日历
	        calendar3.add(Calendar.DAY_OF_MONTH, 0); // 设置为前1天
	        dnow = calendar3.getTime(); // 得到前一天的时间
	        
	        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
	        System.out.println(sdf.format(dBefore));
	        System.out.println(sdf.format(dAfter));
	        System.out.println(sdf.format(dnow));
	        
	        new couponWapper().setValidStartByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dBefore);
	    	new couponWapper().setValidEndByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dAfter);
	    	
	        new couponWapper().setValidStartByCouponCode(userReceiveCouponCall2.getUserReceiveResult().getCouponCode(), dBefore);
	    	new couponWapper().setValidEndByCouponCode(userReceiveCouponCall2.getUserReceiveResult().getCouponCode(), dAfter);
			
	    	getuserexpiringamountBean.setPlatformSource(1);//分销
			getuserexpiringamountBean.setUserId(userId);
			getuserexpiringamountCall.setData(getuserexpiringamountBean);
			getuserexpiringamountCall.callService();	
			//计算面值总值
			String couponValue=new couponbatchWapper().getCouponValueByValidEnd(userId,sdf.format(dnow),getuserexpiringamountBean.getPlatformSource()).stripTrailingZeros().toString();
			
			Logger.verifyEquals("0", getuserexpiringamountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getuserexpiringamountCall.getMessage(), "验证返回Message");
			Logger.verifyEquals(0, getuserexpiringamountCall.getDataErrorCode(), "验证返回Data中的ErrorCode");
			Logger.verifyEquals("null", getuserexpiringamountCall.getDataErrorMessage(), "验证返回Data中的ErrorMessage");
			Logger.verifyEquals(couponValue, getuserexpiringamountCall.getAmount(), "验证返回Data中的Amount");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getUserExpiringAmount_009() {
		Logger.start(true,"获取用户即将过期的优惠券面额-平台券-分销");
		try {
			int userId = TestDataManager.getRandomIntNum(8);
			
			CouponServiceMCallServiceV2 couponMCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createCouponBean.setAcquireCouponMethod(1);
			CreateCouponCall createCouponCall = couponMCallService.createPlatformCoupon(createCouponBean);
			UserReceiveCouponCall userReceiveCouponCall=couponMCallService.receiveCouponInfo(createCouponCall.getBatchCode(),userId);//领取优惠券
			
					
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();
	        Date dnow = new Date();
	        
	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -5); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, 2); // 设置为后2天
	        dAfter = calendar2.getTime(); // 得到后2天的时间
	        
	        Calendar calendar3 = Calendar.getInstance(); // 得到日历
	        calendar3.setTime(dNow);// 把当前时间赋给日历
	        calendar3.add(Calendar.DAY_OF_MONTH, 0); // 设置为前1天
	        dnow = calendar3.getTime(); // 得到前一天的时间
	        
	        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
	        System.out.println(sdf.format(dBefore));
	        System.out.println(sdf.format(dAfter));
	        System.out.println(sdf.format(dnow));
	        
	        new couponWapper().setValidStartByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dBefore);
	    	new couponWapper().setValidEndByCouponCode(userReceiveCouponCall.getUserReceiveResult().getCouponCode(), dAfter);
			
	    	getuserexpiringamountBean.setPlatformSource(1);//分销
			getuserexpiringamountBean.setUserId(userId);
			getuserexpiringamountCall.setData(getuserexpiringamountBean);
			getuserexpiringamountCall.callService();	
			//计算面值总值
			//String couponValue=new couponbatchWapper().getCouponValueByValidEnd(userId,sdf.format(dnow),getuserexpiringamountBean.getPlatformSource()).stripTrailingZeros().toString();
			
			Logger.verifyEquals("0", getuserexpiringamountCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getuserexpiringamountCall.getMessage(), "验证返回Message");
			Logger.verifyEquals(0, getuserexpiringamountCall.getDataErrorCode(), "验证返回Data中的ErrorCode");
			Logger.verifyEquals("null", getuserexpiringamountCall.getDataErrorMessage(), "验证返回Data中的ErrorMessage");
			Logger.verifyEquals("0", getuserexpiringamountCall.getAmount().toString(), "验证返回Data中的Amount");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}